#ifndef JJB_SOLUTION
#define JJB_SOLUTION

#include "node.h"
#include "dataset.h"

#define WEIGHT_MATRIX {{0,1,2,2,2},{1,0,2,2,2},{2,1,0,2,2},{3,2,2,0,2},{4,2,2,2,0}}

class solution
{
public:
    solution() 
        : root(NULL), evaluated(false) {}

    solution(solution* ); 

    ~solution() 
    { if (root) delete(root); }

    void evaluate(dataset* trainSet, dataset* testSet);

    // Tree manipulation functions
    void setRoot(node* tmpRoot) { root = tmpRoot; }
    
    node* getRoot() {return root; }

    double getTrainFitness() 
        { double sum = 0;
          int weight[5][5] = WEIGHT_MATRIX;
          for (int i = 0; i < 5; i++)
             for (int j = 0; j < 5; j++)
                sum += weight[i][j] * confusionTrain[i][j];
          return sum; }

    double getTestFitness() 
        { double sum = 0;
          int weight[5][5] = WEIGHT_MATRIX;
          for (int i = 0; i < 5; i++)
             for (int j = 0; j < 5; j++)
                sum += weight[i][j] * confusionTest[i][j];
          return sum; }

    void display();
    void printTree(node* tmp, int depth);

    int getNumber() { return solutionNum; }
    void setNumber(int tmp) { solutionNum = tmp; }
private:

    node *root;
  
    int solutionNum;
    
    bool evaluated;
    int confusionTrain[5][5];
    int confusionTest[5][5];

    double TrainPD[5];
    double TrainFAR[5];
    double TestPD[5];
    double TestFAR[5];
};
#endif
